﻿Imports System.Data.SqlClient
Public Class XoaSinhVien

    Private _str As String
    Private _maLop As Object
    Dim _code As String

    Sub New(ByVal str As String, ByVal MaLop As Object)
        ' TODO: Complete member initialization 
        _str = str
        _maLop = MaLop
    End Sub

    Private Property Lop_ID As Object

    Private Sub XoaSinhVien_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "SELECT SinhVien_ID,TenSinhVien,GioiTinh,NgaySinh,NoiSinh,NoiOHienTai,KhoaHoc,LyLich,TenLop FROM SinhVien,Lop WHERE Lop_ID=ID_Lop and SinhVien_ID='" + _code + "'"
        Dim rd As SqlDataReader
        rd = cmd.ExecuteReader()
        Dim td As DataTable = New DataTable()
        td.Load(rd)

        Me.txtmsv.Text = td.Rows(0)(0).ToString()
        Me.txttsv.Text = td.Rows(0)(1).ToString()
        Me.mskns.Text = td.Rows(0)(3).ToString()
        Me.txtns.Text = td.Rows(0)(4).ToString()
        Me.txttt.Text = td.Rows(0)(5).ToString()
        Me.txtkh.Text = td.Rows(0)(6).ToString()
        Me.lstll.Items.Add(td.Rows(0)(7).ToString())
        Me.txtlh.Text = td.Rows(0)(8).ToString()
        Dim sex As Integer
        sex = Convert.ToInt16(td.Rows(0)(2))
        If sex = 0 Then
            radioButton1.Checked = True
        Else
            radioButton2.Checked = True
        End If
        con.Close()
    End Sub

    Private Sub button2_Click(sender As System.Object, e As System.EventArgs) Handles button2.Click
        Dim con As SqlConnection = New SqlConnection()
        con.ConnectionString = Ketnoi.str
        con.Open()
        Dim cmd1 As SqlCommand = New SqlCommand()
        Dim cmd2 As SqlCommand = New SqlCommand()
        cmd1.Connection = con
        cmd2.Connection = con
        cmd1.CommandText = "DELETE FROM KetQua Where ID_SinhVien='" + txtmsv.Text + "'"
        cmd2.CommandText = "DELETE FROM SinhVien Where SinhVien_ID='" + txtmsv.Text + "'"
        Dim result As DialogResult
        result = MessageBox.Show("BẠN CÓ MUỐN THAY XÓA THÔNG TIN KHÔNG?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If result = DialogResult.Yes Then
            cmd1.ExecuteNonQuery()
            cmd2.ExecuteNonQuery()
            MessageBox.Show("XÓA THÀNH CÔNG", "THÔNG BÁO")
        End If
        con.Close()
        Me.Close()
        Dim frm As DanhSachSinhVien = New DanhSachSinhVien(Lop_ID)
        frm.Show()

    End Sub

    Private Sub button3_Click(sender As System.Object, e As System.EventArgs) Handles button3.Click
        Me.Close()
        Dim frm As DanhSachSinhVien = New DanhSachSinhVien(Lop_ID)
        frm.Show()

    End Sub

    Private Sub btnXoaKetQuaHocTap_Click(sender As System.Object, e As System.EventArgs) Handles btnXoaKetQuaHocTap.Click
        Dim MaSV As String
        Dim TenSV As String
        MaSV = txtmsv.Text
        TenSV = txttsv.Text
        Dim frm As XoaKetQua = New XoaKetQua(MaSV, TenSV)
        frm.Show()
    End Sub
End Class